/*
206. 反转链表
link:https://leetcode.cn/problems/reverse-linked-list/
给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
*/
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

 //分别记录当前节点 前驱节点 后继节点
struct ListNode* reverseList(struct ListNode* head) {
    struct ListNode* cur = head;
    struct ListNode* pre = NULL;
    struct ListNode* tail = NULL;
    while(cur)
    {
        tail = cur->next;
        cur->next = pre;
        pre = cur;
        cur = tail;
    }
    return pre;
}